package it.progettoso.thread;

import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.widget.Toast;

public class DeleteSmsThread implements Runnable {
	private Context context;
	private String phone="";
	private String body="";

	public DeleteSmsThread(Context context,String phone,String body) {
		this.phone=phone;
		this.context=context;
		this.body=body;
	}

	@Override
	public void run() {
		 //int num=0;
	    	try {
	    		Uri uriSms = Uri.parse("content://sms/");
	    		Cursor c = context.getContentResolver().query(uriSms, null,null,null,null);   
	    		//num=c.getCount()+1;
	    		/*while(context.getContentResolver().query(uriSms, null,null,null,null).getCount()!=num){
	    		}	
	    		if (c != null && c.moveToLast()) { 
	    				context.getContentResolver().delete(uriSms, "address=? and body=?", new String[] {phone,body}); 				
	    		}*/
	    		if(c!=null)
	    		while(context.getContentResolver().delete(uriSms, "address=? and body=?", new String[] {phone,body})<=0){
	    		}	
	  
	    		c.close();
	    	}catch (Exception e) {
	    		Toast.makeText(context,"eccezione:"+e.fillInStackTrace(), Toast.LENGTH_LONG).show(); 
	    	}
	}
	
}
